package game;

import java.awt.Color;
import java.awt.Graphics;

public class VisibleMarine implements VisibleCharacter {

	Graphics g;

	int x, y, width, height;

	Color color;

	Character c;

	public VisibleMarine(Character c, Graphics g, int x, int y, Color color) {
		this.g = g;
		this.color = color;
		width = 50;
		height = 50;
		this.x = x;
		this.y = y;
		this.c = c;

		// Color tmpColor = g.getColor();
		g.setColor(color);
		g.fillRect(x, y, width, height);
		// g.setColor(tmpColor);
	}

	public void move(int x, int y) {
		int newX = this.x + x;
		int newY = this.y + y;
		Color tmpColor = g.getColor();

		g.setColor(color);
		g.clearRect(this.x, this.y, width, height);
		g.fillRect(this.x + x, this.y + y, width, height);
		g.setColor(tmpColor);

		this.x = newX;
		this.y = newY;
	}

	public void remove() {
		g.clearRect(this.x, this.y, width, height);
	}

	public void attaque(Character c) {
		try {
			this.c.attaque(c);
			g.drawLine(x, y, ((VisibleCharacter) c).getX(), ((VisibleCharacter) c).getY());

		} catch (DeathException e) {
			System.out.println(e.getDead().getName()
					+ " est mort !!\n Il a été tué par : "
					+ e.getKiller().getName());
			// ((VisibleBadGuy) e.getDead()).stop();
			// ((VisibleBadGuy) e.getDead()).remove();
		}

	}

	public int getHp() {
		return this.c.getHp();
	}

	public int getSpeed() {
		return this.c.getSpeed();
	}

	public void takeDammage(int dammage) throws DeathException {
		this.c.takeDammage(dammage);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getWidth() {
		return width;
	}

	public String getName() {
		return c.getName();
	}

	public void attaque(VisibleCharacter c) throws DeathException {
		c.takeDammage(this.c.getStrength());
	}
}